package atm;

import java.text.Format;

public class MyTime 
{
	private int minute;
	private int hour;
	private int second;
	
	public MyTime(int hour, int minute, int second)
	{
		setTime(hour,minute, second);
				
	}
	void setTime(int hour,int minute,int second)
	{
		setHour(hour);
		setMinute(minute);
		setSecond(second);
	}

	public int getMinute() {
		return minute;
	}

	public void setMinute(int minute)
	{
		if(minute>=0 && minute<=59)
		this.minute = minute;
		
		else
			throw new IllegalArgumentException("Invalid minute !!!");
	}

	public int getHour() {
		return hour;
	}

	public void setHour(int hour) 
	{
		if(hour>=0 && hour<=23)
		this.hour = hour;
		
		else
			throw new IllegalArgumentException("Invalid hour!!!");
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) 
	{
		if(second>=0 && second<=59)
		this.second = second;
		
		else
			throw new IllegalArgumentException("Invalid second!!!");
	}
	
	public String toString()
	{
		return  String.format("%02d:%02d:%02d",hour,minute,second);
	}
	
	public MyTime nextSecond()
	{
		++second;
		
		if(second==60)
		{
			second=0;
			++minute;
		}
		
		if(minute==60)
		{
			minute=0;
			++hour;
		}
		
		if(hour==24)
		{
			hour=0;
		}
		
		return this;
	}

}
